*Structural-Analysis02.do
****************************************************************************************
**************************Analysis for 1999*********************************************
****************************************************************************************
 clear matrix

*
*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace
clear
set mem 300000
set matsize 800

set more off

*****************This Do-File Runs The Heckman Two-Step Selection Model*****************
*****************Note: Heckman Procedure Uses Reduced-Form Probit***********************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\Selection-Probit_02_df.do"

*****************This Files Run the CTaCS Program***************************************
*****************Note: WS = Wage/Salary SE = Self-Employment Real = Sample *************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsWS02.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSE02.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsReal02.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSED02.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSEH02.do"


***************************Merge CTaCS Output to Master Data****************************


use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-02ws.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxWS 
rename totprovtax totprovtaxWS 
rename tottax tottaxWS

keep pucpid26 totfedtaxWS totprovtaxWS tottaxWS

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsWS.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-02se.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSE 
rename totprovtax totprovtaxSE 
rename tottax tottaxSE

keep pucpid26 totfedtaxSE totprovtaxSE tottaxSE

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsSE.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-02real.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxReal 
rename totprovtax totprovtaxReal
rename tottax tottaxReal

keep pucpid26 totfedtaxReal totprovtaxReal tottaxReal

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsReal", replace

**********
use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-02SED.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSED 
rename totprovtax totprovtaxSED 
rename tottax tottaxSED

keep pucpid26 totfedtaxSED totprovtaxSED tottaxSED

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsSED.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-02SEH.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSEH 
rename totprovtax totprovtaxSEH 
rename tottax tottaxSEH

keep pucpid26 totfedtaxSEH totprovtaxSEH tottaxSEH

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsSEH.dta", replace
***********************
use "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02analysis", clear

sort pucpid26
*drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsWS"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsSE"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsReal"
tab _merge
drop _merge
**********
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsSED"
tab _merge
drop _merge
*
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02ctacsSEH"
tab _merge
drop _merge
**************

*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace

**************Summarize Predicted Earnings and Predicted Taxes**********************

sum  btearningSE btearningE 
bysort selfemp:  sum earng42

sum  tottaxWS tottaxSE tottaxReal
bysort selfemp: sum inctx27 
sum inctx27 

sum  tottaxWS tottaxSE tottaxReal if inva27==0 & male==1
bysort selfemp: sum inctx27 if inva27==0 & male==1
sum inctx27 if inva27==0 & male==1


*
gen taxdif=  ln((tottaxSE )/(tottaxWS))
gen taxdifDH=1  

gen taxU=(tottaxSED)/(tottaxSE)
gen Tax_ratio = (tottaxSE/(btearningSE+other-tottaxSE))
gen taxdifU=  ln(taxU)*Tax_ratio
gen taxdifU2 = (taxU-1)*Tax_ratio

replace tottaxSEH=1 if tottaxSEH==0
gen taxD = (tottaxSEH)/(tottaxSE)
*gen taxD = (tottaxSE)/(tottaxSEH)
gen taxdifD = ln(taxD)*Tax_ratio
gen taxdifD2 = (taxU-1)*Tax_ratio


sum  tottaxSED tottaxSEH tottaxSE if tottaxSEH>0 & tottaxSE>0
drop if tottaxSEH<=0 | tottaxSE<=0  
sum  tottaxSED tottaxSEH tottaxSE  


* Keeping only variables to be used in final   model
keep date  other Tax_ratio taxdifD taxdifD2 taxdifU taxdifU2 other2 rse  DhhE  inctx42 fditx42 pvitx42 inctx27 wkrcp42 spoucearn btearningE btearningSE  incomedif  year pucpid26 puchid25 selfemp inva27 inva42 capgn27   yrschl18 ecage26 age2 wksuem28 health male married   kids immigrant blucol   service newfoundland pei novascotia newbrunswick ontario quebec manitoba saskatchewan alberta bc earng42  wksuem28 udpd42 medx42 rppc42 rspwi42 pen42 oasgi42 cpqpp42 uiben42 capgn27 capgn42 sapis42 ottxm42 cpqpp42 alimo42 rppc42 chfed42 ccar42 alip42 year  kidage1-kidage7 rd yrxfte11  pctincearn whtcol incomedif  taxdif taxdifDH totfedtaxWS totprovtaxWS tottaxWS totfedtaxSE totprovtaxSE tottaxSE totfedtaxReal totprovtaxReal tottaxReal    
 
*SEstdf
*yrxfte11
 
 

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\02analysis", replace

 




  

